package online.inote.naruto.api.access.admin.modules.system.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;
import online.inote.naruto.api.access.admin.modules.base.entity.SignatureEntity;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * @description 系统授权接口实体对象
 * @author XQF.Sui
 * @date 2021/08/06 19:19
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@Entity
@Table(
    name = "naruto_system_auth_api",
    uniqueConstraints =
        @UniqueConstraint(
            columnNames = {AuthInterfaceEntity.Fields.systemId, AuthInterfaceEntity.Fields.apiId}))
public class AuthInterfaceEntity extends SignatureEntity {
  private static final long serialVersionUID = -4027636775555025703L;

  @Id
  @GeneratedValue
  @Column(length = 36)
  private Integer id;

  @NotBlank(message = "系统ID不能为空")
  @Column(nullable = false, length = 36)
  private String systemId;

  @NotBlank(message = "API ID不能为空")
  @Column(nullable = false, length = 36)
  private String apiId;

  @Column(nullable = false)
  private Date createTime;

  @Transient private String classMethod;
  @Transient private Boolean enable;

  public static AuthInterfaceBuilder builder() {
    return new AuthInterfaceBuilder();
  }

  public static class AuthInterfaceBuilder {
    private Integer id;
    private String systemId;
    private String apiId;
    private Date createTime;
    private String classMethod;
    private Boolean enable;

    public AuthInterfaceBuilder id(Integer id) {
      this.id = id;
      return this;
    }

    public AuthInterfaceBuilder systemId(String systemId) {
      this.systemId = systemId;
      return this;
    }

    public AuthInterfaceBuilder apiId(String apiId) {
      this.apiId = apiId;
      return this;
    }

    public AuthInterfaceBuilder createTime(Date createTime) {
      this.createTime = createTime;
      return this;
    }

    public AuthInterfaceBuilder classMethod(String classMethod) {
      this.classMethod = classMethod;
      return this;
    }

    public AuthInterfaceBuilder enable(Boolean enable) {
      this.enable = enable;
      return this;
    }

    public AuthInterfaceEntity build() {
      return new AuthInterfaceEntity(id, systemId, apiId, createTime, classMethod, enable);
    }
  }
}
